<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>账目信息</title>

    <!--data table-->
    <link rel="stylesheet" href="js/data-tables/DT_bootstrap.css" />

    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->

    <style type="text/css">
        #all_light { /*整个弹窗的页面*/
            opacity: 0.8; /*透明度*/
            width: 100%; /*宽度*/
            height: 2300px; /*高度，不能百分百*/
            background: #000; /*背景色*/
            position: absolute;
            top: 0;
            left: 0; /*定位*/
            display: none; /*隐藏*/
            z-index: 2; /*覆盖*/
        }
        #contes { /* 弹框的页面*/
            width: 500px; /*宽度*/
            height: 500px; /*高度*/
            background: #fff; /*背景色*/
            display: none; /*隐藏*/
            z-index: 2; /*覆盖*/
            position: absolute;
            top: 100px;
            left: 400px; /* 定位*/
        }
        input{
            margin-bottom: 10px;
        }
    </style>


</head>

<body class="sticky-header">
<div id="app">
    <section>
        <!-- left side start-->
        <script src="left.js"></script>
        <!-- left side end-->

        <!-- main content start-->
        <div class="main-content" >

            <!-- header section start-->
            <div class="header-section">

                <!--toggle button start-->
                <a class="toggle-btn"><i class="fa fa-bars"></i></a>
                <!--toggle button end-->
            </div>
            <!-- header section end-->

            <!-- page heading start-->
            <div class="page-heading">
                <h3>
                    账目信息
                </h3>
                <ul class="breadcrumb">
                    <li>
                        <a href="#">首页</a>
                    </li>
                    <li>
                        <a href="#">管理</a>
                    </li>
                    <li class="active"> 账目管理 </li>
                </ul>
            </div>
            <!-- page heading end-->

            <!--body wrapper start-->
            <div class="wrapper">
                <div class="row">
                    <label><span><h1 id="dashow"> ==== ==== ==== ==== ==== ==== ====当前公司余额10000 ==== ==== ==== ==== ==== ==== ==== ====</h1></span></label>
                </div>
                <div class="row">
                    <div class="col-sm-12">
                        <section class="panel">

                            <div class="panel-body">
                                <div class="adv-table editable-table ">
                                    <div class="clearfix">
                                        <div class="btn-group">

                                        </div>
                                        <div class="btn-group pull-right">
                                            <button style="background-color: #4cae4c;color: black" onclick="daochuzd()">导出账单信息</button>
                                        </div>
                                    </div>
                                    <div class="space15"></div>


                                    <!-- 表格 -->
                                    <table class="table table-striped table-hover table-bordered"
                                           id="editable-sample">
                                        <thead>
                                        <tr>
                                            <th prop="id">账单号</th>
                                            <th prop="acId">账目账户id</th>
                                            <th prop="msg">账目变动原因</th>
                                            <th prop="createTime">账目变动时间</th>
                                        </tr>
                                        </thead>

                                        <tbody id="newList">

                                        </tbody>
                                    </table>
                                </div>

                            </div>
                            <div col-lg-6>

                                <div class="dataTables_paginate paging_bootstrap pagination">

                                    <ul id="pagination">

                                    </ul>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
            <!--body wrapper end-->
            <!--  入库弹框的div==================================================================================== -->
            <div id="contes" style="">
                <div style="width:500px;height:40px;">
                    <hr>
                    <form style=" margin-left: 100px;" id="dataform-admin">
                        <input type="hidden" id="id" name="id">
                        <input type="hidden" id="addOrSub" name="addOrSub">
                        输入金额   :  <input type="text" value="" id="price"  name="factToUpdate"><br>

                        <button type="button" onclick="submitform()">提交</button>
                        <button type="button" onclick="cancel()">取消</button>

                    </form>
                </div>
            </div>
            <div id="all_light">
            </div>
            <!--  弹框的div==================================================================================== -->

                 <!--body wrapper start-->
            <div class="wrapper">

                <div class="row">
                    <div class="col-sm-12">
                        <section class="panel">

                            <div class="panel-body">
                                <div class="adv-table editable-table ">
                                    <div class="clearfix">
                                        <div class="btn-group">
                                        </div>
                                    </div>
                                    <div class="space15"></div>

                                    <!-- 表格 -->
                                    <table class="table table-striped table-hover table-bordered"
                                           id="editable-sample-admin">
                                        <thead>
                                        <tr>
                                            <th prop="id">账户管理信息号</th>
                                            <th prop="need_to_update">需收/需付</th>
                                            <th prop="fact_to_update">实收/实付</th>
                                            <th prop="owe_price">欠收/欠费</th>
                                            <th prop="update_time">更新时间</th>
                                            <th prop="reid">对应订单号</th>
                                            <th prop="isok">是否结清</th>
                                            <th prop="msg">当前状态信息</th>
                                            <th prop="addOrSub">addOrSub</th>
                                            <th>收费</th>
                                            <th>付费</th>
                                        </tr>
                                        </thead>

                                        <tbody id="newList-admin">

                                        </tbody>
                                    </table>
                                </div>

                            </div>

                        </section>
                    </div>
                </div>
            </div>
            <!--body wrapper end-->


        </div>

    </section>
</div>

<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/jquery-ui-1.9.2.custom.min.js"></script>
<script src="js/jquery-migrate-1.2.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="js/jquery.nicescroll.js"></script>

<!--data table-->
<script type="text/javascript" src="js/data-tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/data-tables/DT_bootstrap.js"></script>

<!--common scripts for all pages-->
<script src="js/scripts.js"></script>

<!--script for editable table-->
<script src="js/editable-table.js"></script>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<!-- END JAVASCRIPTS -->
<!--初始化权限-->
<script src="orders.js"></script>
<!--初始化权限-->
<script>
    window.onload=function (){
        var order;
        $.ajax({
            url:"/users/getOrder",
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                order=res;
                if(order==2){
                    order2();
                }
                if(order==3){
                    order3();
                }
            },
            error:function (){

            }
        })
        $.ajax({
            url:"/account/getPrice",
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                $("#dashow").html("==== ==== ==== ==== ==== ==== ====当前公司余额"+res.data+"元 ==== ==== ==== ==== ==== ==== ==== ====")
            },
            error:function (){

            }
        })
        load();
    }
    var pagination={ //分页信息
        currentPage:1,
        pageSize:5,
        totalPage:10
    }
    //导出账单信息
    function daochuzd(){
        $.ajax({
            url:"/account/daochu",
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
            },
            error:function (){

            }
        })
    }
    //展示列表
    function showList(list,sum,index){
        $('#newList').empty();
        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].acId+"</td>\n" +
                "<td>"+list[i].msg+"</td>\n" +
                "<td>"+list[i].createTime+"</td>\n" +
                "</tr>"
            $("#newList").append(tr);
        }

        $('#pagination').empty();
        for(var i=1;i<=sum;i++){
            if(i==index)var li="<li><button style='color: red' onclick=\"gopage("+i+")\">"+i+"</button></li>";
            else var li="<li><button onclick=\"gopage("+i+")\">"+i+"</button></li>";
            $("#pagination").append(li);
        }
    }


    //序列化Json
    function getFormJson(form) {
        var o = {};
        var a = form
        $.each(a, function () {
            if (o[this.name] !== undefined) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
    //管理
    function cancel(){
        document.getElementById('contes').style.display = 'none';
    }
    function submitform(){
        var serialize = $("#dataform-admin").serializeArray();
        var dataParmas=getFormJson(serialize);
        console.log(dataParmas)
        $.ajax({
            url:"/adc/updatePrice",
            type:"post",
            data: JSON.stringify(dataParmas),
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
               alert(res.msg)
            },
            error:function (){

            }
        })
    }
    function jump(id,addOrSub){
        var price=prompt("请输入金额");
        var dataParmas='{"id":'+id+',"addOrSub":'+addOrSub+',factToUpdate":'+price+'}';
        console.log(dataParmas)
        $.ajax({
            url:"/adc/updatePrice",
            type:"post",
            data: '{"id":'+id+',"addOrSub":'+addOrSub+',"factToUpdate":'+price+'}',
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                alert(res.msg)
                location.reload()
            },
            error:function (){

            }
        })
        // $("#addOrSub").val(addOrSub);
        // $("#id").val(id);
        // document.getElementById('all_light');
        // document.getElementById('contes').style.display = 'block';
    }
    function addMoney(id,addOrSub){
        jump(id,addOrSub)
    }
    function subMoney(id,addOrSub){
        jump(id,addOrSub)
    }
    function showADlist(list){
        $('#newList-admin').empty();
        var hid='pointer-events: none;';
        for(var i=0;i<list.length;i++) {
            var tr="<tr>\n" +
                "<td>"+list[i].id+"</td>\n" +
                "<td>"+list[i].needToUpdate+"</td>\n" +
                "<td>"+list[i].factToUpdate+"</td>\n" +
                "<td>"+list[i].owePrice+"</td>\n" +
                "<td>"+list[i].updateTime+"</td>\n" +
                "<td>"+list[i].reid+"</td>\n" +
                "<td>"+list[i].isok+"</td>\n" +
                "<td>"+list[i].msg+"</td>\n" +
                "<td>"+list[i].addOrSub+"</td>\n" +
                "<td><button id='btn-add"+list[i].id+"'  style='background-color: #55d455' onclick=\"addMoney("+list[i].id+","+list[i].addOrSub+")\">收费</button></td>\n" +
                "<td><button id='btn-sub"+list[i].id+"'  style='background-color: #55d455' onclick=\"subMoney("+list[i].id+","+list[i].addOrSub+")\">付费</button></td>\n" +
                "</tr>"


            $("#newList-admin").append(tr);
            if (list[i].addOrSub==1){
                document.getElementById('btn-sub'+list[i].id+'').style.cssText=hid;
            }else
                document.getElementById('btn-add'+list[i].id+'').style.cssText=hid;
            if(list[i].owePrice<=0){
                document.getElementById('btn-sub'+list[i].id+'').style.cssText=hid;
                document.getElementById('btn-add'+list[i].id+'').style.cssText=hid;
            }
        }
    }
    function getADlist(){
        $.ajax({
            url:"/adc/getlist",
            type:"get",
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                var list=res.data
                showADlist(list)
              },
            error:function (){

            }
        })
    }

    //去xx页面
    function gopage(i){
        pagination.currentPage=i;//修改当前页码
        $.ajax({
            url:"/account/getList",
            type:"POST",
            data:'{"currentPage":"'+pagination.currentPage+'","pageSize":"'+pagination.pageSize+'"}',
            contentType:"application/json;charset=UTF8",
            dataType:"json",
            success:function (res){
                if (res.success){
                    var l=res.data.list//重新赋值
                    var sum=res.data.totalPage;//更新总页数
                    showList(l,sum,i)
                }
                else{
                    alert("查询失败!")
                }
            },
            error:function (){

            }
        })


    }
    function load(){
        gopage(1);
        getADlist();
    }



</script>

</body>
</html>
